package com.tianchi.lexiang.background;

import com.tianchi.lexiang.R;
import com.tianchi.lexiang.background.util.PublicUtil;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class DeleteSong extends Activity implements OnItemClickListener {

	private ListView backgroundSettingList;
	private Button backBtn;

	public PublicUtil publicUtil = PublicUtil.getPulibUtil();
	
	public static DeleteSong deleteSong;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		deleteSong=this;
		setContentView(R.layout.background_setting);
		initView();
	}

	private void initView() {
		backgroundSettingList = (ListView) findViewById(R.id.background_setting_list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, this.getResources().getStringArray(R.array.delete_song));
		backgroundSettingList.setAdapter(adapter);
		backgroundSettingList.setOnItemClickListener(this);
		backBtn = (Button) findViewById(R.id.back_btn);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				DeleteSong.this.finish();
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Intent intent = new Intent();
		switch (position) {
		case 0:
			if (publicUtil.detectionHardDisk()){
				intent.setClass(DeleteSong.this, BatchDeleteSong.class);
				DeleteSong.this.startActivity(intent);
			}
			else
				dialog();
			break;
		case 1:
			if (publicUtil.detectionHardDisk()){
				intent.setClass(DeleteSong.this, SearchDeleteSong.class);
				DeleteSong.this.startActivity(intent);
			}
			else
				dialog();
			break;

		default:
			break;
		}

	}

	private void dialog() {
		AlertDialog.Builder builder = new Builder(DeleteSong.this);
		builder.setMessage(getString(R.string.check_hdd_tip));
		builder.setIcon(android.R.drawable.ic_menu_info_details);
		builder.setTitle(getString(R.string.tip));
		builder.setPositiveButton(getString(R.string.confirm), new Dialog.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}

}
